<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jq test</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f8ff;
        }

        .container {
            padding: 20px;
            text-align: center;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            animation: fadeIn 1s ease-in-out;
        }

        .form-group {
            margin-bottom: 15px;
        }

        .form-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }

        .form-group input {
            width: 100%;
            padding: 8px;
            box-sizing: border-box;
            border: 1px solid #ccc;
            border-radius: 4px;
            transition: border-color 0.3s ease;
        }

        .form-group input:focus {
            border-color: #007BFF;
            outline: none;
        }

        .form-group button {
            padding: 10px 15px;
            background-color: #007BFF;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .form-group button:hover {
            background-color: #0056b3;
        }

        .result {
            margin-top: 20px;
            padding: 10px;
            border: 1px solid #ccc;
            background-color: #f9f9f9;
            border-radius: 4px;
            animation: slideIn 0.5s ease-in-out;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
            }
            to {
                opacity: 1;
            }
        }

        @keyframes slideIn {
            from {
                transform: translateY(20px);
                opacity: 0;
            }
            to {
                transform: translateY(0);
                opacity: 1;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <div class="form-group">
        <label for="username">名称:</label>
        <input type="text" id="username" name="username" required placeholder="请输入名称" >
        <button onclick="submitUsername()" style="margin-top: 10px">匹配</button>
    </div>
    <div class="form-group">
        将在
        <div id="count"></div>
        个小伙伴中随机匹配一位:
        <div class="result" id="result1" style="text-align: left">
            匹配结果：
            <div class="result" id="result">
            </div>
        </div>
    </div>
</div>

<script>
    window.onload = function () {
        getSize();
    }

    function submitUsername() {
        const username = document.getElementById('username').value;
        const xhr = new XMLHttpRequest();
        xhr.open('POST', '/submit?username=' + username, true);
        xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4 && xhr.status === 200) {
                document.getElementById('result').innerText = xhr.responseText;
            } else if (xhr.readyState === 4) {
                document.getElementById('result').innerText = '请求失败';
            }
        };
        xhr.send(JSON.stringify({username: username}));
    }

    function getSize() {
        const username = document.getElementById('username').value;
        const xhr = new XMLHttpRequest();
        xhr.open('POST', '/getCount', true);
        xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4 && xhr.status === 200) {
                document.getElementById('count').innerText = '(' + xhr.responseText + ")";
            } else if (xhr.readyState === 4) {
                document.getElementById('count').innerText = '请求失败';
            }
        };
        xhr.send(JSON.stringify({username: username}));
    }
</script>
</body>
</html>
